﻿/*
 * 
 * CMPF - 26/07/2006
 *
 */

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace Deskalea
{
	/// <summary>
	/// Description of frmDummy.
	/// </summary>
	public partial class frmDummy
	{
		private ContextMenu ctxMenu;
		
		public frmDummy()
		{
			// The InitializeComponent() call is required for Windows Forms designer support.
			InitializeComponent();
		}
		
		#region Making the Form ALT+TAB invisible
		//I'had to make some Windows API calls to make the main form truly invisible
		//Although you couldn't see it, it would still appear as a valid choice when
		//ALT+TABbing
		//
		//Tuve que hacer algunas llamadas a la API de Windows para hacer al formulario 
		//realmente invisible. Aunque no podía verse, seguía apareciendo como opción válida
		//cuando se hacía ALT+TAB
		private const int GWL_EXSTYLE = (-20);
		private const int WS_EX_TOOLWINDOW = 0x80;
		private const int WS_EX_APPWINDOW = 0x40000;

		[DllImport("user32", CharSet=CharSet.Auto)]
		private static extern int GetWindowLong(IntPtr hWnd, int nIndex);

		[DllImport("user32", CharSet=CharSet.Auto)]
		private static extern int SetWindowLong(IntPtr hWnd, int nIndex, int
			dwNewLong);
		#endregion
		
		void FrmDummyLoad(object sender, System.EventArgs e)
		{
			ctxMenu = new ContextMenu();
			notifIcon.Text = "Deskalea"; 
			notifIcon.Visible = true; 
			notifIcon.Icon = new System.Drawing.Icon(GetType(),"deskalea_xp.ico");
			ctxMenu.MenuItems.Clear();
			ctxMenu.MenuItems.Add("Exit",new EventHandler(this.Exit_Click));
			notifIcon.ContextMenu = ctxMenu;				
			//Haciendo el form invisible para ALT+TAB
			SetWindowLong(this.Handle, GWL_EXSTYLE, (GetWindowLong(this.Handle,
				GWL_EXSTYLE) | WS_EX_TOOLWINDOW) & ~WS_EX_APPWINDOW);
		}
		
		protected void Exit_Click(Object sender, System.EventArgs e) 
		{
			this.notifIcon.Visible = false;
			Application.Exit();
		}		
	}//CLASS
}//NAMESPACE
